﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SW2A311_Lib;

namespace Client
{
    /// <summary>
    /// Event klasse, til deling mellem Network og en GUI
    /// </summary>
    public class EventDrivenShare
    {
        #region Dataindkapsling
        /// <summary>
        /// Indkapsling til DataToSendChanged event
        /// </summary>
        public class EncapsulationArgs : EventArgs
        { //indkapsling til data der skal sendes over netværk
            public EncapsulationArgs(EncapsulationClass EncapsulationIn)
            {
                this.Encapsulation = EncapsulationIn;
            }

            public readonly EncapsulationClass Encapsulation;
        }

        /// <summary>
        /// Indkapsling til ChatmessageChanged event
        /// </summary>
        public class ChatMessageArgs : EventArgs
        {
            public ChatMessageArgs(String ChatMessageIn)
            {
                this.ChatMessage = ChatMessageIn;
            }

            public readonly string ChatMessage;
        }

        /// <summary>
        /// Indkapsling til ProjectChanged event.
        /// </summary>
        public class ProjectArgs : EventArgs
        {
            public ProjectArgs(ProjectData ProjectIn)
            {
                this.Project = ProjectIn;
            }

            public readonly ProjectData Project;
        }

        #endregion

        #region Properties

        private EncapsulationClass _encapsulation;
        public EncapsulationClass Encapsulation
        {
            get { return _encapsulation; }
            set
            {
                _encapsulation = value;
                DataToSendChanged(new EncapsulationArgs(value));
            }
        }

        private string _chatMessage;
        public string ChatMessage
        {
            get { return _chatMessage; }
            set
            {
                _chatMessage = value;
                ChatMessageChanged(new ChatMessageArgs(value));
            }
        }

        private ProjectData _project;
        public ProjectData Project
        {
            get { return _project; }
            set
            {
                _project = value;
                ProjectChanged(new ProjectArgs(value));
            }
        }

        #endregion

        #region Event
        /// <summary>
        /// Event der reagere på ændring af propertien Encapsulation
        /// </summary>
        /// <param name="e">Inputtet der sendes videre til alle subscribers</param>
        public event EventHandler<EncapsulationArgs> DataToSendChange = delegate { };
        
        protected virtual void DataToSendChanged(EncapsulationArgs e)
        {
            if (DataToSendChange != null)
                DataToSendChange(this, e);
        }
        /// <summary>
        /// Event der reagere på ændring af propertien ChatMessage
        /// </summary>
        /// <param name="e">Inputtet der sendes videre til alle subscribers</param>
        public event EventHandler<ChatMessageArgs> ChatMessageChange = delegate { };
        
        protected virtual void ChatMessageChanged(ChatMessageArgs e)
        {
            if (ChatMessageChange != null)
                ChatMessageChange(this, e);
        }
        /// <summary>
        /// Event der reagere på ændring af propertien Project
        /// </summary>
        /// <param name="e">Inputtet der sendes videre til alle subscribers</param>
        public event EventHandler<ProjectArgs> ProjectChange = delegate { };
        
        protected virtual void ProjectChanged(ProjectArgs e)
        {
            if (ProjectChange != null)
                ProjectChange(this, e);
        }
        #endregion
    }
}
